package com.tcm.doctor.web.controller;

import com.base.core.exception.ServiceException;
import com.base.core.utils.R;
import com.tcm.doctor.domain.dto.CashDrawsDTO;
import com.tcm.doctor.service.DoctorCashDrawsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/doctor")
@RestController
public class DoctorExtractController {

    @DubboReference(version = "0.0.1-alpha", timeout = 6000, check = false, retries = 3)
    private DoctorCashDrawsService doctorCashDrawsService;

    @GetMapping("/cash/draws/view")
    public R view(@RequestParam("id") Long id) {
        return R.success(doctorCashDrawsService.findById(id));
    }

    @PostMapping("/cash/draws/save")
    public R create(@RequestBody CashDrawsDTO doctorExtractDto) {
        try {
            doctorCashDrawsService.save(doctorExtractDto);
        } catch (ServiceException e) {
            return R.fail(e.getResult().getCode(), e.getMessage());
        } catch (Exception e) {
            return R.fail(e.getMessage());
        }
        return R.success();
    }

}

